package cn.tedu.boyou.acticle.service.impl;

import cn.tedu.boyou.acticle.domain.Region;
import cn.tedu.boyou.acticle.mapper.RegionMapper;
import cn.tedu.boyou.acticle.service.IRegionService;
import cn.tedu.boyou.common.query.RegionQuery;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional  //单体事务控制
public class RegionServiceImpl implements IRegionService{
    @Autowired
    private RegionMapper regionMapper;

    public PageInfo query(RegionQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Region> regions = regionMapper.selectForList(qo);
        return new PageInfo(regions);
    }

    public void saveOrUpdate(Region region) {
        if(region.getId() != null){
            regionMapper.updateByPrimaryKey(region);
        }else {
            regionMapper.insert(region);
        }
    }

    public void delete(Long id) {
        regionMapper.deleteByPrimaryKey(id);
    }

    public void changeHotValue(Long id, Boolean hot) {
        regionMapper.changeHotValue(id,hot);
    }

    public List<Region> queryHotRegion() {
        return regionMapper.selectHotRegion();
    }

}
